home *** CD-ROM | disk | FTP | other *** search
/ CDROM of CDROMs 1994 May / The CD-ROM of CD-ROMs - The Consumer's Guide to CD-ROMs - Walnut Creek May 1994.iso / samples / unix / part4 < prev    next >
Encoding:
Internet Message Format  |  1994-04-12  |  25.7 KB

  1. From: tmatimar@isgtec.com (Ted M A Timar)
  2. Newsgroups: comp.unix.questions,comp.unix.shell,news.answers,comp.answers
  3. Subject: Unix - Frequently Asked Questions (4/7) [Frequent posting]
  4.  
  5. Archive-name: unix-faq/faq/part4
  6. Version: $Id: part4,v 2.2 1993/03/18 23:06:21 tmatimar Exp $
  7.  
  8. These seven articles contain the answers to some Frequently Asked
  9. Questions often seen in comp.unix.questions and comp.unix.shell.
  10. Please don't ask these questions again, they've been answered plenty
  11. of times already - and please don't flame someone just because they may
  12. not have read this particular posting.  Thank you.
  13.  
  14. Many FAQs, including this one, are available on the archive site
  15. rtfm.mit.edu (18.172.1.27) in the directory pub/usenet/news.answers.
  16. The name under which a FAQ is archived appears in the "Archive-Name:"
  17. line at the top of the article.  This FAQ is archived as
  18. "unix-faq/faq/part[1-7]".
  19.  
  20. These articles are divided approximately as follows:
  21.  
  22.       1.*) General questions.
  23.       2.*) Relatively basic questions, likely to be asked by beginners.
  24.       3.*) Intermediate questions.
  25.       4.*) Advanced questions, likely to be asked by people who thought
  26.        they already knew all of the answers.
  27.       5.*) Questions pertaining to the various shells, and the differences.
  28.       6.*) An overview of Unix variants.
  29.       7.*) An comparison of configuration management systems (RCS, SCCS).
  30.  
  31. This article includes answers to:
  32.  
  33.       4.1)  How do I read characters from a terminal without requiring the user
  34.               to hit RETURN?
  35.       4.2)  How do I check to see if there are characters to be read without
  36.               actually reading?
  37.       4.3)  How do I find the name of an open file?
  38.       4.4)  How can an executing program determine its own pathname?
  39.       4.5)  How do I use popen() to open a process for reading AND writing?
  40.       4.6)  How do I sleep() in a C program for less than one second?
  41.       4.7)  How can I get setuid shell scripts to work?
  42.       4.8)  How can I find out which user or process has a file open or is using
  43.             a particular file system (so that I can unmount it?)
  44.       4.9)  How do I keep track of people who are fingering me?
  45.       4.10) Is it possible to reconnect a process to a terminal after it has
  46.             been disconnected, e.g. after starting a program in the background
  47.             and logging out?
  48.       4.11) Is it possible to "spy" on a terminal, displaying the output
  49.             that's appearing on it on another terminal?
  50.  
  51. If you're looking for the answer to, say, question 4.5, and want to skip
  52. everything else, you can search ahead for the regular expression "^4.5)".
  53.  
  54. While these are all legitimate questions, they seem to crop up in
  55. comp.unix.questions or comp.unix.shell on an annual basis, usually
  56. followed by plenty of replies (only some of which are correct) and then
  57. a period of griping about how the same questions keep coming up.  You
  58. may also like to read the monthly article "Answers to Frequently Asked
  59. Questions" in the newsgroup "news.announce.newusers", which will tell
  60. you what "UNIX" stands for.
  61.  
  62. With the variety of Unix systems in the world, it's hard to guarantee
  63. that these answers will work everywhere.  Read your local manual pages
  64. before trying anything suggested here.  If you have suggestions or
  65. corrections for any of these answers, please send them to to
  66. tmatimar@isgtec.com.
  67.  
  68. ----------------------------------------------------------------------
  69.  
  70. Subject: How do I read characters ... without requiring the user to hit RETURN?
  71. Date: Thu Mar 18 17:16:55 EST 1993
  72.  
  73. 4.1)  How do I read characters from a terminal without requiring the user
  74.       to hit RETURN?
  75.  
  76.       Check out cbreak mode in BSD, ~ICANON mode in SysV.
  77.  
  78.       If you don't want to tackle setting the terminal parameters
  79.       yourself (using the "ioctl(2)" system call) you can let the stty
  80.       program do the work - but this is slow and inefficient, and you
  81.       should change the code to do it right some time:
  82.  
  83.       #include <stdio.h>
  84.       main()
  85.       {
  86.         int c;
  87.  
  88.         printf("Hit any character to continue\n");
  89.         /*
  90.          * ioctl() would be better here; only lazy
  91.          * programmers do it this way:
  92.          */
  93.         system("/bin/stty cbreak");        /* or "stty raw" */
  94.         c = getchar();
  95.         system("/bin/stty -cbreak");
  96.         printf("Thank you for typing %c.\n", c);
  97.  
  98.         exit(0);
  99.       }
  100.  
  101.       You might like to check out the documentation for the "curses"
  102.       library of portable screen functions.  Often if you're interested
  103.       in single-character I/O like this, you're also interested in
  104.       doing some sort of screen display control, and the curses library
  105.       provides various portable routines for both functions.
  106.  
  107. ------------------------------
  108.  
  109. Subject: How do I check to see if there are characters to be read ... ?
  110. Date: Thu Mar 18 17:16:55 EST 1993
  111.  
  112. 4.2)  How do I check to see if there are characters to be read without
  113.       actually reading?
  114.  
  115.       Certain versions of UNIX provide ways to check whether characters
  116.       are currently available to be read from a file descriptor.  In
  117.       BSD, you can use select(2).  You can also use the FIONREAD ioctl
  118.       (see tty(4)), which returns the number of characters waiting to
  119.       be read, but only works on terminals, pipes and sockets.  In
  120.       System V Release 3, you can use poll(2), but that only works on
  121.       streams.  In Xenix - and therefore Unix SysV r3.2 and later - the
  122.       rdchk() system call reports whether a read() call on a given file
  123.       descriptor will block.
  124.  
  125.       There is no way to check whether characters are available to be
  126.       read from a FILE pointer.  (You could poke around inside stdio
  127.       data structures to see if the input buffer is nonempty, but that
  128.       wouldn't work since you'd have no way of knowing what will happen
  129.       the next time you try to fill the buffer.)
  130.  
  131.       Sometimes people ask this question with the intention of writing
  132.         if (characters available from fd)
  133.             read(fd, buf, sizeof buf);
  134.       in order to get the effect of a nonblocking read.  This is not
  135.       the best way to do this, because it is possible that characters
  136.       will be available when you test for availability, but will no
  137.       longer be available when you call read.  Instead, set the
  138.       O_NDELAY flag (which is also called FNDELAY under BSD) using the
  139.       F_SETFL option of fcntl(2).  Older systems (Version 7, 4.1 BSD)
  140.       don't have O_NDELAY; on these systems the closest you can get to
  141.       a nonblocking read is to use alarm(2) to time out the read.
  142.  
  143. ------------------------------
  144.  
  145. Subject: How do I find the name of an open file?
  146. Date: Thu Mar 18 17:16:55 EST 1993
  147.  
  148. 4.3)  How do I find the name of an open file?
  149.  
  150.       In general, this is too difficult.  The file descriptor may
  151.       be attached to a pipe or pty, in which case it has no name.
  152.       It may be attached to a file that has been removed.  It may
  153.       have multiple names, due to either hard or symbolic links.
  154.  
  155.       If you really need to do this, and be sure you think long
  156.       and hard about it and have decided that you have no choice,
  157.       you can use find with the -inum and possibly -xdev option,
  158.       or you can use ncheck, or you can recreate the functionality
  159.       of one of these within your program.  Just realize that
  160.       searching a 600 megabyte filesystem for a file that may not
  161.       even exist is going to take some time.
  162.  
  163. ------------------------------
  164.  
  165. Subject: How can an executing program determine its own pathname?
  166. Date: Thu Mar 18 17:16:55 EST 1993
  167.  
  168. 4.4)  How can an executing program determine its own pathname?
  169.  
  170.       Your program can look at argv[0]; if it begins with a "/", it is
  171.       probably the absolute pathname to your program, otherwise your
  172.       program can look at every directory named in the environment
  173.       variable PATH and try to find the first one that contains an
  174.       executable file whose name matches your program's argv[0] (which
  175.       by convention is the name of the file being executed).  By
  176.       concatenating that directory and the value of argv[0] you'd
  177.       probably have the right name.
  178.  
  179.       You can't really be sure though, since it is quite legal for one
  180.       program to exec() another with any value of argv[0] it desires.
  181.       It is merely a convention that new programs are exec'd with the
  182.       executable file name in argv[0].
  183.  
  184.       For instance, purely a hypothetical example:
  185.     
  186.     #include <stdio.h>
  187.     main()
  188.     {
  189.         execl("/usr/games/rogue", "vi Thesis", (char *)NULL);
  190.     }
  191.  
  192.       The executed program thinks its name (its argv[0] value) is
  193.       "vi Thesis".   (Certain other programs might also think that
  194.       the name of the program you're currently running is "vi Thesis",
  195.       but of course this is just a hypothetical example, don't
  196.       try it yourself :-)
  197.  
  198. ------------------------------
  199.  
  200. Subject: How do I use popen() to open a process for reading AND writing?
  201. Date: Thu Mar 18 17:16:55 EST 1993
  202.  
  203. 4.5)  How do I use popen() to open a process for reading AND writing?
  204.  
  205.       The problem with trying to pipe both input and output to an
  206.       arbitrary slave process is that deadlock can occur, if both
  207.       processes are waiting for not-yet-generated input at the same
  208.       time.  Deadlock can be avoided only by having BOTH sides follow a
  209.       strict deadlock-free protocol, but since that requires
  210.       cooperation from the processes it is inappropriate for a
  211.       popen()-like library function.
  212.  
  213.       The 'expect' distribution includes a library of functions that a
  214.       C programmer can call directly.  One of the functions does the
  215.       equivalent of a popen for both reading and writing.  It uses ptys
  216.       rather than pipes, and has no deadlock problem.  It's portable to
  217.       both BSD and SV.  See the next answer for more about 'expect'.
  218.  
  219. ------------------------------
  220.  
  221. Subject: How do I sleep() in a C program for less than one second?
  222. Date: Thu Mar 18 17:16:55 EST 1993
  223.  
  224. 4.6)  How do I sleep() in a C program for less than one second?
  225.  
  226.       The first thing you need to be aware of is that all you can
  227.       specify is a MINIMUM amount of delay; the actual delay will
  228.       depend on scheduling issues such as system load, and could be
  229.       arbitrarily large if you're unlucky.
  230.  
  231.       There is no standard library function that you can count on in
  232.       all environments for "napping" (the usual name for short
  233.       sleeps).  Some environments supply a "usleep(n)" function which
  234.       suspends execution for n microseconds.  If your environment
  235.       doesn't support usleep(), here are a couple of implementations
  236.       for BSD and System V environments.
  237.  
  238.       The following code is adapted from Doug Gwyn's System V emulation
  239.       support for 4BSD and exploits the 4BSD select() system call.
  240.       Doug originally called it 'nap()'; you probably want to call it
  241.       "usleep()";
  242.  
  243.       /*
  244.         usleep -- support routine for 4.2BSD system call emulations
  245.         last edit:    29-Oct-1984    D A Gwyn
  246.       */
  247.  
  248.       extern int    select();
  249.  
  250.       int
  251.       usleep( usec )                /* returns 0 if ok, else -1 */
  252.         long        usec;        /* delay in microseconds */
  253.         {
  254.         static struct            /* `timeval' */
  255.             {
  256.             long    tv_sec;        /* seconds */
  257.             long    tv_usec;    /* microsecs */
  258.             }    delay;        /* _select() timeout */
  259.  
  260.         delay.tv_sec = usec / 1000000L;
  261.         delay.tv_usec = usec % 1000000L;
  262.  
  263.         return select( 0, (long *)0, (long *)0, (long *)0, &delay );
  264.         }
  265.  
  266.       On System V you might do it this way:
  267.  
  268.       /*
  269.       subseconds sleeps for System V - or anything that has poll()
  270.       Don Libes, 4/1/1991
  271.  
  272.       The BSD analog to this function is defined in terms of
  273.       microseconds while poll() is defined in terms of milliseconds.
  274.       For compatibility, this function provides accuracy "over the long
  275.       run" by truncating actual requests to milliseconds and
  276.       accumulating microseconds across calls with the idea that you are
  277.       probably calling it in a tight loop, and that over the long run,
  278.       the error will even out.
  279.  
  280.       If you aren't calling it in a tight loop, then you almost
  281.       certainly aren't making microsecond-resolution requests anyway,
  282.       in which case you don't care about microseconds.  And if you did,
  283.       you wouldn't be using UNIX anyway because random system
  284.       indigestion (i.e., scheduling) can make mincemeat out of any
  285.       timing code.
  286.  
  287.       Returns 0 if successful timeout, -1 if unsuccessful.
  288.  
  289.       */
  290.  
  291.       #include <poll.h>
  292.  
  293.       int
  294.       usleep(usec)
  295.       unsigned int usec;        /* microseconds */
  296.       {
  297.         static subtotal = 0;    /* microseconds */
  298.         int msec;            /* milliseconds */
  299.  
  300.         /* 'foo' is only here because some versions of 5.3 have
  301.          * a bug where the first argument to poll() is checked
  302.          * for a valid memory address even if the second argument is 0.
  303.          */
  304.         struct pollfd foo;
  305.  
  306.         subtotal += usec;
  307.         /* if less then 1 msec request, do nothing but remember it */
  308.         if (subtotal < 1000) return(0);
  309.         msec = subtotal/1000;
  310.         subtotal = subtotal%1000;
  311.         return poll(&foo,(unsigned long)0,msec);
  312.       }
  313.  
  314.       Another possibility for nap()ing on System V, and probably other
  315.       non-BSD Unices is Jon Zeeff's s5nap package, posted to
  316.       comp.sources.misc, volume 4.  It does require a installing a
  317.       device driver, but works flawlessly once installed.  (Its
  318.       resolution is limited to the kernel HZ value, since it uses the
  319.       kernel delay() routine.)
  320.  
  321. ------------------------------
  322.  
  323. Subject: How can I get setuid shell scripts to work?
  324. Date: Thu Mar 18 17:16:55 EST 1993
  325.  
  326. 4.7)  How can I get setuid shell scripts to work?
  327.  
  328.       [ This is a long answer, but it's a complicated and frequently-asked
  329.         question.  Thanks to Maarten Litmaath for this answer, and
  330.         for the "indir" program mentioned below. ]
  331.  
  332.       Let us first assume you are on a UNIX variant (e.g. 4.3BSD or
  333.       SunOS) that knows about so-called `executable shell scripts'.
  334.       Such a script must start with a line like:
  335.  
  336.     #!/bin/sh
  337.  
  338.       The script is called `executable' because just like a real (binary)
  339.       executable it starts with a so-called `magic number' indicating
  340.       the type of the executable.  In our case this number is `#!' and
  341.       the OS takes the rest of the first line as the interpreter for
  342.       the script, possibly followed by 1 initial option like:
  343.  
  344.     #!/bin/sed -f
  345.  
  346.       Suppose this script is called `foo' and is found in /bin,
  347.       then if you type:
  348.  
  349.     foo arg1 arg2 arg3
  350.  
  351.       the OS will rearrange things as though you had typed:
  352.  
  353.     /bin/sed -f /bin/foo arg1 arg2 arg3
  354.  
  355.       There is one difference though: if the setuid permission bit for
  356.       `foo' is set, it will be honored in the first form of the
  357.       command; if you really type the second form, the OS will honor
  358.       the permission bits of /bin/sed, which is not setuid, of course.
  359.  
  360.       ----------
  361.  
  362.       OK, but what if my shell script does NOT start with such a `#!'
  363.       line or my OS does not know about it?
  364.  
  365.       Well, if the shell (or anybody else) tries to execute it, the OS
  366.       will return an error indication, as the file does not start with
  367.       a valid magic number.  Upon receiving this indication the shell
  368.       ASSUMES the file to be a shell script and gives it another try:
  369.  
  370.     /bin/sh shell_script arguments
  371.  
  372.       But we have already seen that a setuid bit on `shell_script' will
  373.       NOT be honored in this case!
  374.  
  375.       ----------
  376.  
  377.       Right, but what about the security risks of setuid shell scripts?
  378.  
  379.       Well, suppose the script is called `/etc/setuid_script', starting
  380.       with:
  381.  
  382.     #!/bin/sh
  383.     
  384.       Now let us see what happens if we issue the following commands:
  385.  
  386.     $ cd /tmp
  387.     $ ln /etc/setuid_script -i
  388.     $ PATH=.
  389.     $ -i
  390.  
  391.       We know the last command will be rearranged to:
  392.  
  393.     /bin/sh -i
  394.  
  395.       But this command will give us an interactive shell, setuid to the
  396.       owner of the script!
  397.       Fortunately this security hole can easily be closed by making the
  398.       first line:
  399.  
  400.     #!/bin/sh -
  401.  
  402.       The `-' signals the end of the option list: the next argument `-i'
  403.       will be taken as the name of the file to read commands from, just
  404.       like it should!
  405.  
  406.       ---------
  407.  
  408.       There are more serious problems though:
  409.  
  410.     $ cd /tmp
  411.     $ ln /etc/setuid_script temp
  412.     $ nice -20 temp &
  413.     $ mv my_script temp
  414.  
  415.       The third command will be rearranged to:
  416.  
  417.     nice -20 /bin/sh - temp
  418.  
  419.       As this command runs so slowly, the fourth command might be able
  420.       to replace the original `temp' with `my_script' BEFORE `temp' is
  421.       opened by the shell!  There are 4 ways to fix this security hole:
  422.  
  423.     1)  let the OS start setuid scripts in a different, secure way
  424.         - System V R4 and 4.4BSD use the /dev/fd driver to pass the
  425.         interpreter a file descriptor for the script
  426.  
  427.     2)  let the script be interpreted indirectly, through a frontend
  428.         that makes sure everything is all right before starting the
  429.         real interpreter - if you use the `indir' program from
  430.         comp.sources.unix the setuid script will look like this:
  431.  
  432.         #!/bin/indir -u
  433.         #?/bin/sh /etc/setuid_script
  434.  
  435.     3)  make a `binary wrapper': a real executable that is setuid and
  436.         whose only task is to execute the interpreter with the name of
  437.         the script as an argument
  438.  
  439.     4)  make a general `setuid script server' that tries to locate the
  440.         requested `service' in a database of valid scripts and upon
  441.         success will start the right interpreter with the right
  442.         arguments.
  443.  
  444.       ---------
  445.  
  446.       Now that we have made sure the right file gets interpreted, are
  447.       there any risks left?
  448.  
  449.       Certainly!  For shell scripts you must not forget to set the PATH
  450.       variable to a safe path explicitly.  Can you figure out why?
  451.       Also there is the IFS variable that might cause trouble if not
  452.       set properly.  Other environment variables might turn out to
  453.       compromise security as well, e.g. SHELL...  Furthermore you must
  454.       make sure the commands in the script do not allow interactive
  455.       shell escapes!  Then there is the umask which may have been set
  456.       to something strange...
  457.  
  458.       Etcetera.  You should realise that a setuid script `inherits' all
  459.       the bugs and security risks of the commands that it calls!
  460.  
  461.       All in all we get the impression setuid shell scripts are quite a
  462.       risky business!  You may be better off writing a C program instead!
  463.  
  464. ------------------------------
  465.  
  466. Subject: How can I find out which user or process has a file open ... ?
  467. Date: Thu Mar 18 17:16:55 EST 1993
  468.  
  469. 4.8)  How can I find out which user or process has a file open or is using
  470.       a particular file system (so that I can unmount it?)
  471.  
  472.       Use fuser (system V), fstat (BSD), ofiles (public domain) or
  473.       pff (public domain).  These programs will tell you various things
  474.       about processes using particular files.
  475.  
  476.       A port of the 4.3 BSD fstat to Dynix, SunOS and Ultrix
  477.       can be found in archives of comp.sources.unix, volume 18.
  478.  
  479.       pff is part of the kstuff package, and works on quite a few systems.
  480.       Instructions for obtaining kstuff are provided in question 3.10.
  481.  
  482. ------------------------------
  483.  
  484. Subject: How do I keep track of people who are fingering me?
  485. From: jik@pit-manager.MIT.EDU (Jonathan I. Kamens)
  486. From: malenovi@plains.NoDak.edu (Nikola Malenovic)
  487. Date: Mon, 23 Nov 1992 16:01:45 -0600
  488.  
  489. 4.9)  How do I keep track of people who are fingering me?
  490.  
  491.       Generally, you can't find out the userid of someone who is
  492.       fingering you from a remote machine.  You may be able to
  493.       find out which machine the remote request is coming from.
  494.       One possibility, if your system supports it and assuming
  495.       the finger daemon doesn't object, is to make your .plan file a
  496.       "named pipe" instead of a plain file.  (Use 'mknod' to do this.)
  497.  
  498.       You can then start up a program that will open your .plan file
  499.       for writing; the open will block until some other process (namely
  500.       fingerd) opens the .plan for reading.  Now you can whatever you
  501.       want through this pipe, which lets you show different .plan
  502.       information every time someone fingers you.
  503.  
  504.       Of course, this may not work at all if your system doesn't
  505.       support named pipes or if your local fingerd insists
  506.       on having plain .plan files.
  507.  
  508.       Your program can also take the opportunity to look at the output
  509.       of "netstat" and spot where an incoming finger connection is
  510.       coming from, but this won't get you the remote user.
  511.  
  512.       Getting the remote userid would require that the remote site be
  513.       running an identity service such as RFC 931.  There are now three
  514.       RFC 931 implementations for popular BSD machines, and several
  515.       applications (such as the wuarchive ftpd) supporting the server.
  516.       For more information join the rfc931-users mailing list,
  517.       rfc931-users-request@kramden.acf.nyu.edu.
  518.  
  519.       There are three caveats relating to this answer.  The first is
  520.       that many NFS systems won't recognize the named pipe correctly.
  521.       This means that trying to read the pipe on another machine will
  522.       either block until it times out, or see it as a zero-length file,
  523.       and never print it.
  524.  
  525.       The second problem is that on many systems, fingerd checks that
  526.       the .plan file contains data (and is readable) before trying to
  527.       read it.  This will cause remote fingers to miss your .plan file
  528.       entirely.
  529.  
  530.       The third problem is that a system that supports named pipes
  531.       usually has a fixed number of named pipes available on the
  532.       system at any given time - check the kernel config file and
  533.       FIFOCNT option.  If the number of pipes on the system exceeds the
  534.       FIFOCNT value, the system blocks new pipes until somebody frees
  535.       the resources.  The reason for this is that buffers are allocated
  536.       in a non-paged memory.
  537.  
  538. ------------------------------
  539.  
  540. Subject: Is it possible to reconnect a process to a terminal ... ?
  541. Date: Thu Mar 18 17:16:55 EST 1993
  542.  
  543. 4.10) Is it possible to reconnect a process to a terminal after it has
  544.       been disconnected, e.g. after starting a program in the background
  545.       and logging out?
  546.  
  547.       Most variants of Unix do not support "detaching" and "attaching"
  548.       processes, as operating systems such as VMS and Multics support.
  549.       However, there are two freely redistributable packages which can
  550.       be used to start processes in such a way that they can be later
  551.       reattached to a terminal.
  552.  
  553.       The first is "screen," which is described in the
  554.       comp.sources.unix archives as "Screen, multiple windows on a CRT"
  555.       (see the "screen-3.2" package in comp.sources.misc, volume 28.)
  556.       This package will run on at least BSD, System V r3.2 and SCO UNIX.
  557.  
  558.       The second is "pty," which is described in the comp.sources.unix
  559.       archives as a package to "Run a program under a pty session" (see
  560.       "pty" in volume 23).  pty is designed for use under BSD-like
  561.       system only.
  562.  
  563.       Neither of these packages is retroactive, i.e. you must have
  564.       started a process under screen or pty in order to be able to
  565.       detach and reattach it.
  566.  
  567. ------------------------------
  568.  
  569. Subject: Is it possible to "spy" on a terminal ... ?
  570. Date: Thu Mar 18 17:16:55 EST 1993
  571.  
  572. 4.11) Is it possible to "spy" on a terminal, displaying the output
  573.       that's appearing on it on another terminal?
  574.  
  575.       There are a few different ways you can do this, although none
  576.       of them is perfect:
  577.  
  578.       * kibitz allows two (or more) people to interact with a shell
  579.         (or any arbitary program).  Uses include:
  580.  
  581.     - watching or aiding another person's terminal session;
  582.     - recording a conversation while retaining the ability to
  583.       scroll backwards, save the conversation, or even edit it
  584.       while in progress;
  585.     - teaming up on games, document editing, or other cooperative
  586.       tasks where each person has strengths and weakness that
  587.       complement one another.
  588.  
  589.         kibitz comes as part of the expect distribution.  See question 3.9.
  590.  
  591.         kibitz requires permission from the person to be spyed upon.  To
  592.         spy without permission requires less pleasant approaches:
  593.  
  594.       * You can write a program that grovels through Kernel structures
  595.         and watches the output buffer for the terminal in question,
  596.         displaying characters as they are output.  This, obviously, is
  597.         not something that should be attempted by anyone who does not
  598.         have experience working with the Unix kernel.  Furthermore,
  599.         whatever method you come up with will probably be quite
  600.         non-portable.
  601.  
  602.       * If you want to do this to a particular hard-wired terminal all
  603.         the time (e.g. if you want operators to be able to check the
  604.         console terminal of a machine from other machines), you can
  605.         actually splice a monitor into the cable for the terminal.  For
  606.         example, plug the monitor output into another machine's serial
  607.         port, and run a program on that port that stores its input
  608.         somewhere and then transmits it out *another* port, this one
  609.         really going to the physical terminal.  If you do this, you have
  610.         to make sure that any output from the terminal is transmitted
  611.         back over the wire, although if you splice only into the
  612.         computer->terminal wires, this isn't much of a problem.  This is
  613.         not something that should be attempted by anyone who is not very
  614.         familiar with terminal wiring and such.
  615.  
  616. ------------------------------
  617.  
  618. End of unix/faq Digest part 4 of 7
  619. **********************************
  620.  
  621. -- 
  622. Ted Timar - tmatimar@isgtec.com
  623.  
  624.